<?php

namespace App\Exceptions;

use App\Api\Helpers\ApiResponse;
use Exception;
use Illuminate\Http\Request;
use Throwable;

class InternalException extends Exception
{
    use ApiResponse;

    protected $msgForUser;

    public function __construct(string $message, string $msgForUser = "系统错误", int $code = 500)
    {
        parent::__construct($message, $code);
        $this->msgForUser = $msgForUser;
    }

    public function render(Request $request)
    {
        if ($request->expectsJson()) {
            $this->internalError($this->msgForUser);
        }

        // 非json请求: 这里可以设置错误返回的页面
    }
}
